<script setup lang="ts">
import { getFileList, getFile } from "@/api/search";

const props: any = defineProps({
  comProps: {
    type: Object,
  },
});
const previewLists = ref([]);
const emit = defineEmits(["close"]);
const handleClose = () => {
  emit("close");
};
const get_file = async (path: any) => {
  if (!path) return;
  try {
    let res: any = await getFile({
      filePath: path,
    });
    let blob = new Blob([res]);
    return URL.createObjectURL(blob);
  } catch (err) {
    return "";
  }
};
// console.log("props", props.preview);
watch(
  props.comProps,
  (val) => {
    // console.log("val", val);
    if (val?.filePath) {
      get_file(val.filePath).then((res) => {
        previewLists.value[0] = res;
      });
    }
  },
  { immediate: true }
);
</script>

<template>
  <el-image-viewer
    :url-list="previewLists"
    hide-on-click-modal
    @close="handleClose"
  />
</template>

<style lang="scss" scoped></style>
